1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : news/classes/class.NewsCategoryVotings.inc.php
5 : - Modulgruppe: News
6 : - Beschreibung: Klasse für die News-Kategorie Umfragen.
7 : - Version: 1.1.2.4, 24/01/08
8 : - Autor(en): Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 :
24 1 : require_once ("class.newscategory.inc.php");
25 :
26 : /**
27 : * Klasse für die News-Kategorie Umfragen.
28 : * @package eStudy.News
29 : * @version 1.1.2.4, 24/01/08
30 : * @author Corinna Kropf <corinna.kropf@mni.fh-giessen.de>
31 : */
32 1 : class NewsCategoryVotings extends NewsCategory
33 : {
34 : /**
35 : * Cache Objekt zur Abfrage von Modulinstallationen (Performance Tweak)
36 : * @var array
37 : */
38 : private $installCacheObject;
39 : /**
40 : * HTML-Template
41 : * @var Template
42 : */
43 : private $newsTemplate;
44 : /**
45 : * Konstruktor
46 : */
47 : public function __construct($catID, $courses, $categorySettings = null, $cacheObject = null)
48 : {
49 0 : parent::__construct($catID, $courses, $categorySettings);
50 0 : $this->installCacheObject = $cacheObject;
51 0 : $this->newsTemplate = new Template(PATH_TO_ROOT."news/templates/newsvoting.html");
52 0 : }
53 : /**
54 : * Muss angepasst werden, falls Modulgruppen umbenannt werden!
55 : * @see NewsCategory
56 : */
57 : public function isInstalled($courseID)
58 : {
59 0 : return Utilities::isInstalled("votings", $courseID, $this->installCacheObject);
60 : }
61 : /**
62 : * @see NewsCategory
63 : */
64 : public function canSelectPeriod() {
65 0 : return true;
66 : }
67 : /**
68 : * @see NewsCategory
69 : */
70 : public function getNewsHeaderTitle($courseID = null, $type = null) {
71 0 : if(isset($this->news))
72 0 : {
73 0 : $newsCount = $this->news["count"];
74 0 : if ($newsCount > 1) $title = sprintf($this->translate->_("%1\$s Umfragen"), $newsCount);
75 0 : elseif ($newsCount == 1) $title = $this->translate->_("1 Umfrage");
76 0 : }
77 0 : else $title = $this->translate->_("Keine neuen Umfragen");
78 :
79 0 : return $title;
80 : }
81 :
82 : /**
83 : * @see NewsCategory
84 : */
85 : protected function getNewsByPeriod($courseID, $from, $to, $lastvisit, $usergroup = null) {
86 : // Neue Mitteilungen
87 0 : if (isset($courseID) && isset($lastvisit) && isset($usergroup) && isset($this->coursePreferences))
88 0 : {
89 0 : if(!is_numeric($courseID) || !is_numeric($lastvisit) || !is_numeric($usergroup)) return null;
90 :
91 0 : global $db;
92 0 : $this->news = array();
93 0 : $userid = isset($_SESSION['userid']) ? Data::toMysql( $_SESSION['userid'] ) : -999999;
94 :
95 : // Foyer-Umfragen werden mit Kurs-ID -1 in der votings-Tabelle gespeichert
96 : $sql = "SELECT * FROM votings "
97 : ."WHERE Active=1 "
98 0 : ."AND CourseID='".($courseID ? $courseID : "-1") ."' "
99 0 : ."AND StartTime>='".($this->getPeriod($courseID, $lastvisit) -86399) ."' "
100 0 : ."ORDER BY StartTime DESC";
101 0 : $this->news["data"] = $db->get_results($sql, ARRAY_A);
102 0 : if ($db->num_rows) {
103 0 : $this->news["count"] = $db->num_rows;
104 0 : $count = count($this->news["data"]);
105 0 : for ($i = 0 ; $i < $count ; $i++) {
106 0 : $voting = $this->news["data"][$i];
107 : // Entsprechend verlinken, wenn der Benutzer (nicht) abgestimmt hat
108 : // bzw. nicht verlinken, wenn Umfrage abgelaufen und Auswertung nicht für Studenten sichtbar
109 0 : if ($voting["Finish"] > time()) {
110 0 : $db->get_var("SELECT * FROM voting_user WHERE VotingID='$voting[VotingID]' AND UserID='$userid'");
111 0 : if (!$db->num_rows && ($usergroup == STUDENT || $usergroup == ALUMNUS)) $voting["aktion"] = "vote";
112 0 : else if ($voting["Visibility"] > 0 || ($usergroup != STUDENT && $usergroup != ALUMNUS && $usergroup != SCHUELER && $usergroup != GAST))
113 0 : $voting["aktion"] = "result";
114 0 : } else if ($voting["Visibility"] > 0 || ($usergroup != STUDENT && $usergroup != ALUMNUS && $usergroup != SCHUELER && $usergroup != GAST))
115 0 : $voting["aktion"] = "result";
116 0 : else $voting["aktion"] = "erledigt";
117 : // Wenn der User Dozent, Hilfsadmin, Admin ist
118 0 : if ($usergroup != STUDENT && $usergroup != ALUMNUS && $usergroup != SCHUELER && $usergroup != GAST) {
119 : // Zur Sicherheit, denn falls noch keine Stimme abgegeben wurde und das Ergebnis
120 : // angezeigt wird, gibt es einen Fehler im Voting-Modul
121 0 : $db->get_col("SELECT UserID FROM voting_user WHERE VotingID='".$voting["VotingID"]."'");
122 0 : $voting["voted"] = $db->num_rows;
123 0 : }
124 0 : $this->news["data"][$i] = $voting;
125 0 : }
126 0 : } else $this->news = null;
127 0 : }
128 :
129 0 : return $this->news;
130 : }
131 : /**
132 : * @see NewsCategory
133 : * @todo Refacs und I18N
134 : */
135 : protected function echoNewsEntry($entry, $courseID, $usergroup = null)
136 : {
137 0 : if(!isset($entry) || !isset($courseID) /*|| !isset($usergroup)*/) return;
138 :
139 0 : $votingName = Data::toHTML($entry["Name"], false);
140 0 : $votingState = ($entry["aktion"] == "erledigt" ? ";font-style:italic" : "");
141 0 : $votingDesc = Data::toHTML(Utilities::chopText($entry["Description"], 150), false);
142 : // Wenn der User ein Student oder Dozent im Foyer ist
143 0 : if ($usergroup == STUDENT || $usergroup == ALUMNUS || $usergroup == SCHUELER || $usergroup == GAST || $usergroup == SEKRETARIAT || ($_SESSION["course"] == 0 && $usergroup == DOZENT && $entry["voted"])) {
144 0 : if ($entry["aktion"] != "erledigt") {
145 0 : $link = PATH_TO_ROOT."voting/voting."
146 0 : .($usergroup == DOZENT ? "teacher" : "user")
147 0 : .".php?VotingID=$entry[VotingID]&aktion=$entry[aktion]";
148 : // aus dem Foyer in eine Umfrage
149 0 : if ($courseID && $courseID != $_SESSION["course"]) $link.= "&changeToCourse=$courseID";
150 0 : $voteAction = ($entry["aktion"] == "vote")? "Stimme abgeben" : "Auswertung";
151 0 : $votingInfo = "<a href='$link' title='Zur Umfrage'>$voteAction</a>";
152 0 : } else $votingInfo = "Erledigt.";
153 0 : } else {
154 0 : if ($entry["voted"]) {
155 0 : $link = PATH_TO_ROOT."voting/voting.teacher.php?VotingID=$entry[VotingID]&aktion=result";
156 : // aus dem Foyer in eine Umfrage
157 0 : if ($courseID && $courseID != $_SESSION["course"]) $link.= "&changeToCourse=$courseID";
158 0 : $votingInfo = "<a href='$link' title='Zur Auswertung'>Auswertung</a>";
159 0 : } else {
160 0 : $votingInfo = "Noch keine Stimme abgegeben";
161 : }
162 : }
163 0 : eval($this->newsTemplate->GetTemplate());
164 0 : }
165 : }
|